package com.skit.mine.ui;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.skit.common.base.BaseActivity;
import com.skit.common.config.RouteConfig;
import com.skit.mine.R;
import com.skit.mine.databinding.UserActivityMainBinding;
import com.skit.mine.span.HtmlTextSpan;


@Route(path = RouteConfig.UserRoute.USER_MAIN)
public class MainActivity extends BaseActivity {
    private UserActivityMainBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        statusBar();//状态栏相关
        binding = DataBindingUtil.setContentView(this, R.layout.user_activity_main);//DataBinding
        binding.setLifecycleOwner(this);//生命周期拥有者
        binding.setBgUrl("file:///android_asset/login_background.jpg");//背景图片，ImageViewBindingAdapter中的方法
        //点击登录按钮
        binding.userButton.setOnClickListener(v -> {
            //使用ARouter的navigation方法
            ARouter.getInstance().build(RouteConfig.UserRoute.USER_LOGIN).navigation();
            finish();
        });
        //HtmlTextSpan
        HtmlTextSpan htmlTextSpan = HtmlTextSpan.setHtmlText(binding.userAgreementTextView, R.string.user_agreement);
        htmlTextSpan.setOnClickListener(view -> {
            Toast.makeText(this, "用户协议被点击", Toast.LENGTH_SHORT).show();
        });

    }

    private void statusBar() {
        Window window = getWindow();
//        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//状态栏透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//21表示5.0
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //23表示6.0
//                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                if (Build.VERSION.SDK_INT >= 27) {//27表示8.1
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
                } else {
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }
            } else {
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                window.setNavigationBarColor(getResources().getColor(R.color.colorAccent));
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//如果小于6.0将状态栏透明
            }
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    }

}
